<?php

namespace App\Trip\Enums\Plane;

use Exception;

enum PlaneRefundTypes: int
{
    //1 默认自主取消 , 2 航变 4 病退,8 疫情 16 航司拒载
    case REFUND_TYPE_VOLUNTARILY   = 1;
    case REFUND_TYPE_FLIGHT_CHANGE = 2;
    case REFUND_TYPE_SICK          = 4;
    case REFUND_TYPE_EPIDEMIC      = 8;// 将废弃

    public static function defaultType(): int
    {
        return self::default()->value;
    }

    public static function default(): PlaneRefundTypes
    {
        return PlaneRefundTypes::REFUND_TYPE_VOLUNTARILY;
    }

    public function detail(): array
    {
        return match ($this) {
            self::REFUND_TYPE_VOLUNTARILY                           => [
                "reason"     => $this->getReason(),
                "reason_uy"  => $this->getReasonUy(),
                "need_proof" => 0,
                "is_show"    => 1,
                "will"       => 1,
            ],
            self::REFUND_TYPE_FLIGHT_CHANGE, self::REFUND_TYPE_SICK => [
                "reason"     => $this->getReason(),
                "reason_uy"  => $this->getReasonUy(),
                "need_proof" => 0,
                "is_show"    => 1,
                "will"       => 0,
            ],
            self::REFUND_TYPE_EPIDEMIC                              => [
                "reason"     => $this->getReason(),
                "reason_uy"  => $this->getReasonUy(),
                "need_proof" => 0,
                "is_show"    => 0,
                "will"       => 0,
            ],
        };
    }

    public function getReason(): string
    {
        return match ($this) {
            self::REFUND_TYPE_VOLUNTARILY   => "自愿退票",
            self::REFUND_TYPE_FLIGHT_CHANGE => "航变退票",
            self::REFUND_TYPE_SICK          => "病退退票",
            self::REFUND_TYPE_EPIDEMIC      => "疫情退票",
        };
    }

    /**
     * @throws Exception
     */
    public function getReasonUy(): string
    {
        return trans2uy($this->getReason());
    }
}
